<?PHP 
include_once 'setup/setup.php';
/* count */
$query="SELECT count(*) FROM e_puser";
$rs = $dbh->query($query);
$total =  $rs->fetchColumn();	

switch($_GET['act'])
{
	case 'del':
				$stmt = $dbh->prepare("DELETE FROM e_puser WHERE u_id=?");
				$stmt->bindParam(1,$_GET['g'],PDO::PARAM_INT );
				$stmt->execute();
				break;
	case "set":
				$stmt = $dbh->prepare("UPDATE e_puser SET u_ischeck='1' WHERE u_id=?");
				$stmt->bindParam(1,$_GET['g'],PDO::PARAM_INT );
				$stmt->execute();				
				break;

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.2.0/build/reset-fonts-grids/reset-fonts-grids.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.3.0/build/base/base-min.css">
<link href="style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>使用者列表</title>
</head>
<body>
<div id="man">
<div class="h_line">使用者列表</div>
<div style="padding:5px;">
| <a href="post_list.php">電子報列表</a> | 使用者列表 | <a href="post.php">新增電子報</a> | <a href="#3">發送測試</a> |</div>
<div style=" padding:10px" align="center">
  每頁顯示：<?php echo $READ_NUM;?>筆 / 總筆數：<?php echo $total;?></div>
<table width="95%" border="0" align="center">
  <tr>
    <td width="17%" bgcolor="#99CCCC"><strong>姓 名</strong></td>
    <td width="50%" bgcolor="#99CCCC"><strong>學校單位</strong></td>
    <td width="11%" align="center" nowrap="nowrap" bgcolor="#99CCCC"><strong>是否老師</strong></td>
    <td width="10%" align="center" nowrap="nowrap" bgcolor="#99CCCC"><strong>教師會</strong></td>
    <td width="12%" align="center" bgcolor="#99CCCC"><strong>動 作</strong></td>
  </tr>
<?php 
	
    if($_GET['p']==0)$_GET['p']=1;									
		$page_count=ceil($total/$READ_NUM);
	if($_GET['p']==1)
		$start_num=0;
	else
 		$start_num=($_GET['p']-1)*$READ_NUM;  
	
	
	$sth = $dbh->prepare("SELECT * FROM e_puser ORDER BY u_id desc LIMIT ?,?");
	$sth->bindParam(1,$start_num,PDO::PARAM_INT );
	$sth->bindParam(2,$READ_NUM,PDO::PARAM_INT);
	$sth->execute();
  	$sth->setFetchMode(PDO::FETCH_ASSOC);
	$res = $sth->fetchAll();
	#print_r($res);
?>
<?php if(!$res){?>
<tr>
    <td colspan="5" align="center" valign="middle"><strong>目前系統尚無資料</strong></td>
    </tr>
<?php } else { // if end ?>
<?php 
foreach ($res as $v){
?>
  
  <tr>
    <td nowrap="nowrap"><a href="mailto:<?php echo $v['u_mail'];?>"><?php echo $v['u_name'];?></a>：[<?php echo $v['u_ischeck']?'已確認':'未確認';?>]</td>
    <td><?php echo $v['u_dep'];?></td>
    <td align="center"><?php echo $v['u_teac']?'有':'無';?></td>
    <td align="center"><?php echo $v['u_hasteac']?'有':'無';?></td>
    <td><a href="?act=del&g=<?php echo $v['u_id'];?>">刪除</a> | <a href="?act=set&g=<?php echo $v['u_id'];?>">核準</a> </td>
  </tr>
<?php
 	}//foreach end 
}//if end 
?> 
  <tr>
    <td colspan="5">
<?php 
 /* 顯示分頁 */
if($_GET['p']!=1) printf("<a href='%s?p=%d'> 【上一頁】</a>",$_SERVER['PHP_SELF'],$_GET['p']-1);
for($i=1;$i<=$page_count;$i++)
{
	if($i==$_GET['p']){
		echo " $i ";	
	}else{
		echo " <a href='$_SERVER[PHP_SELF]?p=$i'>$i</a> ";	
	}
}											
if($_GET['p']<$page_count) printf("<a href='%s?p=%d'>【下一頁】</a>",$_SERVER['PHP_SELF'],$_GET['p']+1);
?>
</td>
    </tr>

</table>
</div>
</body>
</html>

